<%@ Page language="vb" CodeFile="changeClient.aspx.vb" Inherits="changeClient_aspx_vb" %>

<%
    rowNumber = 0
    vehicleID = Request.QueryString("vehicleID")
    vehicleID = CLng(vehicleID)
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        dbOpen()
        RecSet = Conn.Execute("Select v.countryID, c.client, c.cin, c.street, c.zipCode, c.city, c.areaCode, c.telephone, c.email From (tblVehicle v INNER JOIN tblClient c ON c.clientID = v.clientID) Where v.vehicleID = " & vehicleID & "")
        If Not RecSet.EOF Then 
            countryID = RecSet.Fields("countryID").Value
            client = RecSet.Fields("client").Value
            cin = RecSet.Fields("cin").Value
            street = RecSet.Fields("street").Value
            zipCode = RecSet.Fields("zipCode").Value
            city = RecSet.Fields("city").Value
            areaCode = RecSet.Fields("areaCode").Value
            telephone = RecSet.Fields("telephone").Value
            email = RecSet.Fields("email").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Over()
        strJS = ""
        strJS = strJS + "[""client"", ""==''""],"
        strJS = strJS + "[""cin"", ""==''""]"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>CHANGE LEASE TAKER<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='changeClient.aspx?do=selectionSave&vehicleID=" & vehicleID & "' method='post'>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Lease taker:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='clientID' id='clientID'>")
        Response.Write("<option value=''> Select an existing lease taker  ")
        dbOpen()
        RecSet = Conn.Execute("Select clientID, client From tblClient Where countryID = " & countryID & " Order By client")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                listClientID = RecSet.Fields("clientID").Value
                listClient = RecSet.Fields("client").Value
                Response.Write("<option value='" & listClientID & "'> " & listClient & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='changeClient.aspx?do=save&vehicleID=" & vehicleID & "&countryID=" & countryID & "' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr><td colspan='3'>If you can't find the specific lease taker above, please create a new one in the form below.</td></tr>")
        Response.Write("<tr><td class='formBold'>Lease taker:</td><td align='right'><input type='text' name='client' id='client' value='" & client & "' size='40' maxlength='50'></td><td><div id='error_client' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Corporate identity number:</td><td align='right'><input type='text' name='cin' id='cin' value='" & cin & "' size='40' maxlength='50'></td><td><div id='error_cin' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' value='" & street & "' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipcode' id='zipcode' value='" & zipCode & "' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' value='" & city & "' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Areacode:</td><td align='right'><input type='text' name='areacode' id='areacode' value='" & areaCode & "' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Telephone:</td><td align='right'><input type='text' name='telephone' id='telephone' value='" & telephone & "' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>E-mail:</td><td align='right'><input type='text' name='email' id='email' value='" & email & "' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>CURRENT LEASE TAKER<hr class='hrHeadline'></td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Lease taker:</td><td align='right'>" & client & "</td></tr>")
        Response.Write("<tr><td>CIN:</td><td align='right'>" & cin & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Street:</td><td align='right'>" & street & "</td></tr>")
        Response.Write("<tr><td>Zipcode:</td><td align='right'>" & zipCode & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>City:</td><td align='right'>" & city & "</td></tr>")
        Response.Write("<tr><td>Areacode:</td><td align='right'>" & areaCode & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Telephone:</td><td align='right'>" & telephone & "</td></tr>")
        Response.Write("<tr><td>E-mail:</td><td align='right'>" & email & "</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("<tr><td colspan='2'><br></td></tr>")
        Response.Write("<tr><td class='headline' colspan='2'>INFORMATION<hr class='hrHeadline'></td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td colspan='2'><font color='red'>OBS!</font> When you click on ""Save"", the current lease taker will be replaced with a new one for this lease contract only. Note that you can not undo this change, and a record over passed lease takers for this specific lease contract will not be saved.</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        vehicleID = Request.QueryString("vehicleID")
        countryID = Request.QueryString("countryID")
        vehicleID = CLng(vehicleID)
        countryID = CLng(countryID)
        client = Request.Form("client")
        cin = Request.Form("cin")
        street = Request.Form("street")
        zipCode = Request.Form("zipcode")
        city = Request.Form("city")
        areaCode = Request.Form("areaCode")
        telephone = Request.Form("telephone")
        email = Request.Form("email")
        userID = fragusLeasingUserID
        If Len(client) > 0 Then 
            client = Trim(client)
            client = Replace(CStr(client), "'", "")
            client = Replace(CStr(client), """", "")
            client = Replace(CStr(client), "<", "")
            client = Replace(CStr(client), ">", "")
            client = Replace(CStr(client), "=", "")
        End IF
        If Len(cin) > 0 Then 
            cin = Trim(cin)
            cin = Replace(CStr(cin), "'", "")
            cin = Replace(CStr(cin), """", "")
            cin = Replace(CStr(cin), "<", "")
            cin = Replace(CStr(cin), ">", "")
            cin = Replace(CStr(cin), "=", "")
        End IF
        If Len(street) > 0 Then 
            street = Trim(street)
            street = Replace(CStr(street), "'", "")
            street = Replace(CStr(street), """", "")
            street = Replace(CStr(street), "<", "")
            street = Replace(CStr(street), ">", "")
            street = Replace(CStr(street), "=", "")
        End IF
        If Len(zipCode) > 0 Then 
            zipCode = Trim(zipCode)
            zipCode = Replace(CStr(zipCode), "'", "")
            zipCode = Replace(CStr(zipCode), """", "")
            zipCode = Replace(CStr(zipCode), "<", "")
            zipCode = Replace(CStr(zipCode), ">", "")
            zipCode = Replace(CStr(zipCode), "=", "")
        End IF
        If Len(city) > 0 Then 
            city = Trim(city)
            city = Replace(CStr(city), "'", "")
            city = Replace(CStr(city), """", "")
            city = Replace(CStr(city), "<", "")
            city = Replace(CStr(city), ">", "")
            city = Replace(CStr(city), "=", "")
        End IF
        If Len(areaCode) > 0 Then 
            areaCode = Trim(areaCode)
            areaCode = Replace(CStr(areaCode), "'", "")
            areaCode = Replace(CStr(areaCode), """", "")
            areaCode = Replace(CStr(areaCode), "<", "")
            areaCode = Replace(CStr(areaCode), ">", "")
            areaCode = Replace(CStr(areaCode), "=", "")
        End IF
        If Len(telephone) > 0 Then 
            telephone = Trim(telephone)
            telephone = Replace(CStr(telephone), "'", "")
            telephone = Replace(CStr(telephone), """", "")
            telephone = Replace(CStr(telephone), "<", "")
            telephone = Replace(CStr(telephone), ">", "")
            telephone = Replace(CStr(telephone), "=", "")
        End IF
        If Len(email) > 0 Then 
            email = Trim(email)
            email = Replace(CStr(email), "'", "")
            email = Replace(CStr(email), """", "")
            email = Replace(CStr(email), "<", "")
            email = Replace(CStr(email), ">", "")
            email = Replace(CStr(email), "=", "")
        End IF
        dbOpen()
        Conn.Execute("Insert Into tblClient (userID, countryID, client, cin, street, zipcode, city, areacode, telephone, email) Values(" & userID & "," & countryID & ",'" & client & "','" & cin & "','" & street & "','" & zipCode & "','" & city & "','" & areaCode & "','" & telephone & "','" & email & "')")
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("SELECT MAX(clientID) AS clientID FROM tblClient")
        intClientID = RecSet.Fields("clientID").Value
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        Conn.Execute("Update tblVehicle Set clientID = " & intClientID & " Where vehicleID = " & vehicleID & "")
        dbClose()
        Response.Redirect("editVehicle.aspx?vehicleID=" & vehicleID & "")
    ElseIf Request.QueryString("do") = "selectionSave" Then 
        vehicleID = Request.QueryString("vehicleID")
        intClientID = Request.Form("clientID")
        vehicleID = CLng(vehicleID)
        If Len(intClientID) = 0 Then
            Response.Redirect("changeClient.aspx?vehicleID=" & vehicleID & "")
        Else
            intClientID = CLng(intClientID)
            dbOpen()
            Conn.Execute("Update tblVehicle Set clientID = " & intClientID & " Where vehicleID = " & vehicleID & "")
            dbClose()
            Response.Redirect("editVehicle.aspx?vehicleID=" & vehicleID & "")
        End If
    End IF
%>
